package dryven.compiletime.apt;

import java.io.IOException;
import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.StandardLocation;

@SupportedAnnotationTypes({"*"})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class ViewFileProcessor extends AbstractProcessor {

	@Override
	public boolean process(Set<? extends TypeElement> annotations,
			RoundEnvironment roundEnv) {
		
		try {
			FileObject f = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "config", "main.xml");
			char[] buf = new char[5];
			f.openReader(false).read(buf);
			String buffer = new String(buf);
			if(!buffer.equals("hello")) {
				processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR, "hohoho");
			} else {
				processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.WARNING, "all is good");
			}
		} catch (IOException e) {
			processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR, "error reading file: "+e.getMessage());
		}
		return false;
	}

}
